<?php
global $username ;
global $password;
global $usernametype;
$username=  $_POST['username'];
$password =  md5($_POST['password']);
$conn = connectDB();
$count=selectmembre($username,$password);
if($count==1)
{
	$_SESSION['pseudo']=$username;
	$smarty->assign('bodycontent',selectcontent("home"));
	$_SESSION['_login'] = $username;
	$_SESSION['_pass'] = $password;
	$result=selectmembreInfo($username,$password);
	$row = mysql_fetch_array($result);
	$_SESSION['_id']=$row['id_membre'];
	if ($username=="admin") {
		$menu =  file_get_contents('templates/menuadmin.tpl');
		$smarty->assign('menu',$menu);
		//$smarty->assign('bodycontent',"Bievenue admin");
		$usernametype=0;
		$_SESSION['_type'] = 0;
		
	}
	else {

		$menu =  file_get_contents('templates/menustudent.tpl');
		$smarty->assign('menu',$menu);
		//$smarty->assign('bodycontent',"student");
		$usernametype=1;
		$_SESSION['_type'] = 1;
	}

}
else{

	$count=selectprofessor($username,$password);
	if($count==1)
	{  
		$_SESSION['pseudo']=$username;
		$_SESSION['_login'] = $username;
		$_SESSION['_pass'] = $password;
		$menu  = file_get_contents('templates/menuteacher.tpl');
		$smarty->assign('menu',$menu);
		$smarty->assign('bodycontent',selectcontent("home"));
		//$smarty->assign('bodycontent',"professeur");
		$usernametype=2;
		$_SESSION['_type'] = 2;
		$_SESSION['_id']=selectIDprofessor($username,$password);
	}

	else{

		$menu  = file_get_contents('templates/menu.tpl');
		$smarty->assign('menu',$menu);
		$smarty->assign('bodytitle',"Vous avez oublier votre mot de passe");
		$bodydinamiccontent = file_get_contents('templates/passwordforgotten.tpl');
		$smarty->assign('bodycontent',$bodydinamiccontent);
		$rightcontent  = file_get_contents('templates/connect.tpl');
		$smarty->assign('sidebarfirstelement',$rightcontent);
		//$smarty->assign('bodycontent',"votre login ".$username." ou votre mot de passe est incorrect");

	}
}

?>